/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package acousticfield3d.gui;

import acousticfield3d.utils.Parse;

/**
 *
 * @author am14010
 */
public class SimulationConfigForm extends javax.swing.JFrame {
    final MainForm mf;
    
    public SimulationConfigForm(MainForm mf) {
        this.mf = mf;
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel40 = new javax.swing.JLabel();
        mediumSpeedText = new javax.swing.JTextField();
        particleDensityText = new javax.swing.JTextField();
        mediumDensityText = new javax.swing.JTextField();
        jLabel37 = new javax.swing.JLabel();
        jLabel41 = new javax.swing.JLabel();
        particleSpeedText = new javax.swing.JTextField();
        jLabel42 = new javax.swing.JLabel();
        mediumCombo = new javax.swing.JComboBox();
        particleCombo = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Sim parameters");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jLabel40.setText("Medium speed:");

        mediumSpeedText.setText("340");
        mediumSpeedText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mediumSpeedTextActionPerformed(evt);
            }
        });

        particleDensityText.setText("25");
        particleDensityText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                particleDensityTextActionPerformed(evt);
            }
        });

        mediumDensityText.setText("1.2");
        mediumDensityText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mediumDensityTextActionPerformed(evt);
            }
        });

        jLabel37.setText("Medium density:");

        jLabel41.setText("Particle speed:");

        particleSpeedText.setText("2400");
        particleSpeedText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                particleSpeedTextActionPerformed(evt);
            }
        });

        jLabel42.setText("Particle density:");

        mediumCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "air", "water" }));
        mediumCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mediumComboActionPerformed(evt);
            }
        });

        particleCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "expanded polysterinere", "polysterinere", "water" }));
        particleCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                particleComboActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel37)
                            .addComponent(jLabel40)
                            .addComponent(jLabel41))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(mediumDensityText)
                            .addComponent(particleSpeedText)
                            .addComponent(mediumSpeedText)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel42)
                        .addGap(18, 18, 18)
                        .addComponent(particleDensityText))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(mediumCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(particleCombo, 0, 170, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel40)
                    .addComponent(mediumSpeedText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel37)
                    .addComponent(mediumDensityText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel41)
                    .addComponent(particleSpeedText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel42)
                    .addComponent(particleDensityText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(mediumCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(particleCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void mediumSpeedTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mediumSpeedTextActionPerformed
        mf.needUpdate();
    }//GEN-LAST:event_mediumSpeedTextActionPerformed

    private void particleDensityTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_particleDensityTextActionPerformed
        mf.needUpdate();
    }//GEN-LAST:event_particleDensityTextActionPerformed

    private void mediumDensityTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mediumDensityTextActionPerformed
        mf.needUpdate();
    }//GEN-LAST:event_mediumDensityTextActionPerformed

    private void particleSpeedTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_particleSpeedTextActionPerformed
        mf.needUpdate();
    }//GEN-LAST:event_particleSpeedTextActionPerformed

    private void mediumComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mediumComboActionPerformed
        final int index = mediumCombo.getSelectedIndex();
        if (index == 0){ //air
            mediumSpeedText.setText( 340 + "");
            mediumDensityText.setText( 1.14 + "");
        }else if (index == 1){ //water
            mediumSpeedText.setText( 1500 + "");
            mediumDensityText.setText( 1000 + "");
        }
    }//GEN-LAST:event_mediumComboActionPerformed

    private void particleComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_particleComboActionPerformed
        final int index = particleCombo.getSelectedIndex();
        if (index == 0){ //EPS
            particleSpeedText.setText( 900 + "");
            particleDensityText.setText( 25 + "");
        }else if (index == 1){ //Polysterine
            particleSpeedText.setText( 3500 + "");
            particleDensityText.setText( 33 + "");
        }else if (index == 2){ //water
            particleSpeedText.setText( 1500 + "");
            particleDensityText.setText( 1000 + "");
        }
    }//GEN-LAST:event_particleComboActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        guiToObj();
        setVisible( false );
    }//GEN-LAST:event_formWindowClosing

    public void objToGUI(){
        mediumSpeedText.setText( mf.simulation.getMediumSpeed() + "");
        mediumDensityText.setText( mf.simulation.getMediumDensity() + "");
        particleSpeedText.setText( mf.simulation.getParticleSpeed() + "");
        particleDensityText.setText( mf.simulation.getParticleDensity() + "");
    }
    
    public void guiToObj(){
       mf.simulation.setMediumSpeed( Parse.toFloat(mediumSpeedText.getText()));
       mf.simulation.setMediumDensity( Parse.toFloat(mediumDensityText.getText()));
       mf.simulation.setParticleSpeed( Parse.toFloat(particleSpeedText.getText()));
       mf.simulation.setParticleDensity( Parse.toFloat(particleDensityText.getText()));
    }
    
    public float getMediumSpeed(){
        return Parse.toFloat( mediumSpeedText.getText() );
    }
    public float getMediumDensity(){
        return Parse.toFloat( mediumDensityText.getText() );
    }
    public float getParticleSpeed(){
        return Parse.toFloat( particleSpeedText.getText() );
    }
    public float getParticleDensity(){
        return Parse.toFloat( particleDensityText.getText() );
    }
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel40;
    private javax.swing.JLabel jLabel41;
    private javax.swing.JLabel jLabel42;
    private javax.swing.JComboBox mediumCombo;
    private javax.swing.JTextField mediumDensityText;
    private javax.swing.JTextField mediumSpeedText;
    private javax.swing.JComboBox particleCombo;
    private javax.swing.JTextField particleDensityText;
    private javax.swing.JTextField particleSpeedText;
    // End of variables declaration//GEN-END:variables
}
